﻿using Generic.App.Application.Contracts.Dto;
using Generic.App.Application.Contracts.Service;
using Generic.App.Domain.Entity;
using Generic.App.Domain.Manager;
using Generic.Domain.Shared.Exception;
using Generic.Domain.Shared.Const;
using Volo.Abp.Domain.Repositories;

namespace Generic.App.Application.Service
{
    public class AppTokenGreyService : BaseApplicationService<App_Account>, IAppTokenGreyService
    {
        private readonly IRepository<App_TokenGrey, string> _appTokenGreyRepository;
        private readonly App_TokenGreyManager _appTokenGreyManager;

        public AppTokenGreyService(IRepository<App_TokenGrey, string> appTokenGreyRepository, App_TokenGreyManager appTokenGreyManager)
        {
            _appTokenGreyRepository = appTokenGreyRepository;
            _appTokenGreyManager = appTokenGreyManager;
        }

        public async Task<List<string>> GetTokenGreyListAsync()
        {
            return (await _appTokenGreyRepository.GetQueryableAsync()).Select(s => s.Token).ToList();
        }

        public async Task<AppTokenGreyDto> InsertAsync(string token, string operateUser)
        {
            var entity = new App_TokenGrey { Token = token };
            await _appTokenGreyManager.Check_UniqueAsync(entity);
            SetInsertBy(entity, operateUser);
            var result = await _appTokenGreyRepository.InsertAsync(entity);
            return ObjectMapper.Map<App_TokenGrey, AppTokenGreyDto>(result);
        }
    }
}
